package LeetCode;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class LC_554_BrickWall {

    public static void main(String[] args) {

    }

    public class Solution {
        public int leastBricks(List<List<Integer>> wall) {
            Map<Integer, Integer> widths = new HashMap<>();
            int minNum = wall.size();
            for (List<Integer> rows : wall) {
                int sum = 0;
                for (int i = 0; i < rows.size() - 1; i++) {
                    sum += rows.get(i);
                    int num = widths.getOrDefault(sum, 0);
                    widths.put(sum, ++num);
                    minNum = Math.min(minNum, wall.size() - num);
                }
            }
            return minNum;
        }
    }

}